package com.wr.springbootRabbitMq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitmq配置类
 */
@Configuration
public class RabbitMqTopicConfig {

    // 1、声明交换机
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("topic-order-exchange");
    }

    //2、声明队列
    @Bean
    public Queue smsTopicQueue(){
        return new Queue("sms.topic.queue");
    }
    @Bean
    public Queue emailTopicQueue(){
        return new Queue("email.topic.queue");
    }
    @Bean
    public Queue duanxinTopicQueue(){
        return new Queue("duanxin.topic.queue");
    }

    //3、绑定交换机与队列

    @Bean
    public Binding smsTopicBinding(){
        return BindingBuilder.bind(smsTopicQueue()).to(topicExchange()).with("#.sms.#");
    }
    @Bean
    public Binding emailTopicBinding(){
        return BindingBuilder.bind(emailTopicQueue()).to(topicExchange()).with("*.email.#");
    }
    @Bean
    public Binding duanxinTopicBinding(){
        return BindingBuilder.bind(duanxinTopicQueue()).to(topicExchange()).with("#.duanxin.#");
    }
}
